Skip to content

Look up the external IP over HTTPS when --external-ip is not set - #365

Merged
SDL-A1 merged 2 commits into
Rustock-dev:mainfrom
ida3m0n:external-ip-lookup
Nov 17, 2026
Merged

SDL-A1 merged 2 commits into
Rustock-dev:mainfrom
ida3m0n:external-ip-lookup

Conversation

@ida3m0n

@ida3m0n ida3m0n commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

With no --external-ip the node advertises 127.0.0.1: it syncs, but peers can't dial it. rskj avoids this by looking up its public IP at startup. This does the same.

Behaviour

  • On mainnet and testnet, an unset --external-ip is resolved from --ip-check-url (default https://checkip.amazonaws.com). off disables it.
  • HTTPS with certificate and hostname verification. Plain http:// is rejected.
  • One 5 s deadline, 4 KiB response cap, no redirects or retries.
  • Any failure falls back to 127.0.0.1 with a warning.
  • Only public IPv4 answers are accepted (IANA special-purpose registry).
  • No lookup in one-shot modes (--verify-state, --measure-block-reads), on regtest or closed networks, or when --external-ip is set.

Breaking change

--external-ip and [node] external_ip now take IPv4 only and reject IPv6 at parse time. The discovery and P2P listeners bind IPv4 only, so an IPv6 address never gave a reachable node.

Dependencies

TLS (tokio-rustls, webpki-roots, ring) is now in every build: 8 extra crates in the default tree. They were already in Cargo.lock behind the optional smtp feature, so no new packages or versions are added. TLS is needed because over plain HTTP an on-path attacker could choose the advertised address.

Tests

  • cargo test -p rustock-cli: 66 unit + 2 integration pass, with and without --features smtp. rustock-networking: 142 pass.
  • A local TLS server with committed test certificates covers trusted, wrong-host and untrusted certificates, a plaintext server on an https:// URL, a stalled handshake, a stalled response, an oversized response, and an IPv6 answer.
  • Two integration tests run the binary against a counting listener and assert that --verify-state and --measure-block-reads make no lookup. Moving the lookup before them makes both fail.
  • Clippy -D warnings is clean for default and smtp. cargo deny passes, including advisories.

Note

Behind NAT the lookup returns the outbound address. The P2P TCP port and the discovery UDP port (P2P + 1) still have to be forwarded.

On mainnet and testnet an unset --external-ip is resolved from
--ip-check-url (default https://checkip.amazonaws.com) with certificate and
hostname verification, a single 5 s deadline and a 4 KiB response cap. Any
failure falls back to 127.0.0.1 with a warning; "off" disables the lookup.

Only public IPv4 answers are accepted, checked against the IANA special-purpose
registry. The listeners are IPv4-only, so --external-ip and its config key now
take an IPv4 address and reject IPv6.

The lookup runs after the one-shot modes, which never start networking.
@SDL-A1
SDL-A1 merged commit a5c18c6 into Rustock-dev:main Nov 17, 2026
7 checks passed
ColbySerpa pushed a commit to HORNET-Storage/Rustock that referenced this pull request Nov 18, 2026
The repository already said to screen foreign code before reading it for correctness. It did not say how, and the how is the part that matters: cargo build and cargo test execute a contributor's code as the developer, with their SSH keys, their gh token and write access to /var/lib/rustock, before a line has been read. The node in production runs hardened under systemd; the development machine does not. Merging was never the dangerous step.

Adds three questions answerable from the diff alone -- new [[package]] entries in Cargo.lock, build-time surfaces (build.rs, .cargo/config.toml, rust-toolchain.toml, proc macros), and non-Rust executables. All three clean means reading the diff is the whole review. Any one dirty means the build belongs in a throwaway container, whoever the author appears to be.

Singles out .cargo/config.toml because it is the quietest: a runner, linker or alias there is arbitrary command execution that reads as configuration rather than code. This repository has none, so one appearing in a pull request is a flag by itself. Also notes that rust-analyzer runs build.rs and expands proc macros when a project is opened, so an editor is an execution vector too.

Written while reviewing Rustock-dev#365 and Rustock-dev#366, which the checklist was then applied to: Rustock-dev#365 came out clean on all three, Rustock-dev#366 dirty on the third, and the four Docker and shell files were read line by line as a result.

The .gitignore entries are unrelated housekeeping: the SPV wallet lives outside this tree, and these are a second line of defence. Root-anchored so a crate directory named client or server is unaffected, and the /dist/ and /bin/ entries from Rustock-dev#366 are preserved.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ColbySerpa added a commit to HORNET-Storage/Rustock that referenced this pull request Nov 18, 2026
Upstream's four pull requests since 169ef57: the external IP looked up
over HTTPS when --external-ip is not set (Rustock-dev#365), the node run from a
prebuilt binary in Docker and configured from .env (Rustock-dev#366), libz-sys
moved past its heap-overflow advisory (Rustock-dev#367), and CLAUDE.md on
screening an outside pull request without running it (Rustock-dev#373).

Three files conflicted:

- crates/cli/Cargo.toml: both sides added tokio-rustls (ring, tls12)
  and webpki-roots, upstream's for the external-IP lookup and this
  branch's for --import. They are listed once, under one comment for
  both, beside this branch's serde_json and sha2. Cargo.lock gains no
  package over upstream's.
- deny.toml: both sides rewrote the note on webpki-roots' licence. It
  now names every use: the external-IP lookup, Rootstock's server for
  --import, a stable minimum gas price's web source, and lettre under
  the smtp feature.
- crates/cli/src/main.rs: both sides' modules are kept.
ColbySerpa added a commit to HORNET-Storage/Rustock that referenced this pull request Nov 18, 2026
Upstream's tests of the lookup (Rustock-dev#365) start their servers on 127.0.0.1
and look up https://localhost:<port>/ with half a second to spare.
Windows resolves localhost to ::1 first and takes two seconds to refuse
a connection, so the lookup was still being refused on ::1 when the half
second ran out: twelve of the tests failed on Windows, where this
branch's CI runs them.

The servers now listen where localhost resolves first, which the lookup
tries first, on every OS. The test of a lookup with nothing listening is
refused on both addresses, four seconds on Windows, and is given ten.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants